import { http } from './index'
import { Message } from 'element-ui'
// 登录
export function login(data){
    return http('login','POST',data)
}
// 获取权限列表
export function getMenus(){
    return http('menus','GET')
}
// 获取用户数据列表
export function getUser(params){
    return http('users','GET',{},params)
}
// 添加用户
export function addUsers(data){
    return http('users','POST',data)
}
// 修改用户状态
export function updateState(params){
    return http('users/'+params.uId+'/state/'+params.type,'put',{},params)
}
// 根据id查询用户信息
export function catUsers(id){
    return http('users/'+id,'GET').then(res => {
        return res.data;
    })
}
// 编辑用户提交
export function submitUsers(id,data){
    return http('users/'+id,'put',data)
}
// 删除单个用户
export function removeUsers(id){
    return http('users/'+id,'delete')
}
// 角色列表
export function rolesList(){
    return http('roles','GET')
}
// 分配用户角色
export function propRoles(id,rid){
    return http(`users/${id}/role`,'PUT',{rid})
}
// 删除角色指定权限
export function deleteRight(roleId,rightId){
    return http(`roles/${roleId}/rights/${rightId}`,'DELETE')
}
// 获取权限列表树
export function getAllRightsTree() {
    return http(`rights/tree`,'GET')
}
// 角色授权
export function editRightIds(roleId, rids) {
    return http(`roles/${roleId}/rights`, 'POST', {rids}).then(res=>{
        Message({
            showClose: true,
            message: res.meta.msg,
            type: 'success'
        })
        return res.data;
    })
}  
// 添加角色
export function addRoles(data) {
    return http('roles','POST',data)
}
// 编辑提交角色
export function submitRoles(id,data){
    return http('roles/'+id,'put',data)
}
// 根据id查询角色
export function catRoles(id){
    return http('roles/'+id,'GET').then(res => {
        return res.data;
    })
}
// 删除角色
export function removeRoles(id){
    return http('roles/'+id,'delete')
}
// 获取权限列表
export function getAllRightsList() {
    return http(`rights/list`,'GET')
}
// 商品列表数据
export function goodsList(params) {
    return http('goods','GET',{},params)
}
// 编辑提交商品
export function submitGoods(id,data){
    return http('goods/'+id,'PUT',data)
}
// 根据id查询商品
export function getGoods(id){
    return http('goods/'+id,'GET').then(res=>{
        return res.data;
    })
}
// 商品数据列表
export function categoriesList(type=3){
    return http('categories','GET',{},{type})
}
// 添加商品分类
export function addCate(data){
    return http('categories','POST',data).then(res => {
        Message({
            showClose: true,
            message: res.meta.msg,
            type: 'success'
        })
        return res.data
    })
}
// 删除商品
export function removeGoods(id){
    return http('goods/'+id,'delete')
}
// 参数列表
export function getCatParamsList(id,sel='many'){
    return http(`categories/${id}/attributes`,'GET',{},{
        sel
    }).then(res=>{
        return res.data
    })
}
// 添加商品
export function addGoods(data){
    return http('goods','POST',data).then(res=>{
        Message({
            showClose: true,
            message: res.meta.msg,
            type: 'success'
        })
        return res.data;
    })
}
// 编辑提交参数(添加删除参数标签)
export function addCatParams(id,attrId,data){
    return http(`categories/${id}/attributes/${attrId}`,'PUT',data).then(res=>{
        Message({
            showClose: true,
            message: res.meta.msg,
            type: 'success'
        })
        return res.data
    })
}
// 编辑提交分类
export function submitCates(id,data){
    return http('categories/'+id,'PUT',data).then(res=>{
        Message({
            showClose: true,
            message: res.meta.msg,
            type: 'success'
        })
        return res.data
    })
}
// 删除分类
export function removeCates(id){
    return http('categories/'+id,'DELETE').then(res=>{
        Message({
            showClose: true,
            message: res.meta.msg,
            type: 'success'
        })
        return res.data
    })
}
// 订单数据列表
export function orderList(data){
    return http('orders','GET',{},data).then(res=>{
        return res.data
    })
}
// 基于时间统计（折线图）
export function getExcharts(){
    return http('reports/type/1','GET').then(res=>{
        return res.data;
    })
}
// 添加动态参数或者静态属性
export function setParams(id,data){
    return http(`categories/${id}/attributes`,'POST',data).then(res => {
        Message({
            showClose: true,
            message: res.meta.msg,
            type: 'success'
        })
        return res.data;
    })
}
// 删除参数
export function removeParams(id,attrId){
    return http(`categories/${id}/attributes/${attrId}`,'DELETE').then(res=>{
        Message({
            showClose: true,
            message: res.meta.msg,
            type: 'success'
        })
        return res.data
    })
}
// 商品数据列表加分页
export function catePageList(pagenum,pagesize){
    return http('categories','GET',{},{type:3,pagenum,pagesize}).then(res=>{
        return res.data
    })
}